<?php

class AddressController extends Ext_Controller_SecureAction
{
    public function indexAction()
	{
       	$user = new CartWS_Model_Address();
       /* $where = str_replace( 
        	"%s", 
        	$this->view->escape( $this->_request->getParam( 'key' )),
        	"username like '%%s%' OR email like '%%s%'"  	);
        */
       	//$where = null; 
       	
        $data = $user->fetchAll();
        
        //Zend_Debug::dump( $user->fetchAll()->address_id) ; exit;
        $mod = new CartWS_Model_DbTable_Address();
         
        $paginator = Ext_Paginator::factory( $data );
        $paginator->setCurrentPageNumber( $this->_getParam('page') );
        
        $this->view->paginator = $paginator;
    }
    public function createAction()
    {
        $request = $this->getRequest();
        $form = new CartPanel_Form_User();

        if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
                $model = new CartWS_Model_User( $form->getValues() );
                $model->save();
                return $this->_helper->redirector('index');
            }
        }
        $this->view->form = $form;
    }

    public function updateAction()
    {
        $request = $this->getRequest();
        $form = new CartPanel_Form_User();
		$model = new CartWS_Model_User();
		$userData = $model->find( $request->id );
        if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
                $model = new CartWS_Model_User( $form->getValues() );
                $model->save();
                return $this->_helper->redirector('index');
            }
        } else {
        	$form->populate( $userData->toArray() );
        }
        $this->view->form = $form;
    }
    
}



